<?php
/**
 * Created by PhpStorm.
 * User: huangpeng3
 * Date: 2018/1/29
 * Time: 下午4:23
 */

namespace Home\Model;

use Think\Model;

class RobotModel extends Model
{

    protected $tableName = 'robot';

    public function getAll($uid)
    {
        $cur = M();
//        $rst = $this->where('uid=' . $uid)->order('id desc')->select();
        $sql = "SELECT r.id rid, r.uid, r.`name` rname, r.state, r.private, r.ctime, s.id sid, s.`name` sname, m.id mid FROM robot r LEFT JOIN ref_robot_strategy ref ON r.id = ref.rid LEFT JOIN strategies s ON ref.sid = s.id LEFT JOIN ref_robot_madatory ref2 ON r.id = ref2.rid LEFT JOIN mandatory m ON ref2.mid = m.id WHERE r.uid = " .$uid;
        $rst = $cur->query($sql);
        if (isset($rst)) {
            $rtn = array();
            foreach ($rst as $k => $v) {
                array_push($rtn, $v);
            }
            return $rtn;
        } else {
            return -1;
        }
    }
}